import uuid
import datetime
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy import Column, String, DateTime
from sqlalchemy.ext.declarative import declarative_base


Base = declarative_base()


def generate_uuid():
    return uuid.uuid4().hex


class ML(Base):
    """机器学习配置
    训练任务与训练的结果存elasticsearch 设计到 str==> int 数据量比较大
    """
    __tablename__ = 'ml'
    id = Column(String, primary_key=True, default=generate_uuid, comment='机器学习ID')

    name = Column(String, nullable=False, comment='机器学习名')
    type = Column(String, nullable=False, comment='机器学习类型')
    datasource = Column(JSONB, default={}, comment='数据源')
    params = Column(JSONB, default={}, comment='训练参数')

    created_at = Column(DateTime, default=datetime.datetime.utcnow, comment='创建时间')
    updated_at = Column(DateTime, default=datetime.datetime.utcnow, onupdate=datetime.datetime.utcnow,
                        comment='更新时间')
